#!/bin/bash
set -x
curDir=`dirname $BASH_SOURCE`
curDir=`realpath ${curDir}`
rootdir=${curDir}/../../
rtidbIp=127.0.0.1
rtidbPort=9526
rtidbTTL=1
threads=10
target=5000


source ${curDir}/../common.sh
pkgname=pipelineTool-0.1.0.tar.gz

testOut=${rootdir}/test-output
pipelineDir=${testOut}/pipelineTool
if [ ! -d ${pipelineDir} ]; then
    execshell "wget http://pkg.4paradigm.com/tools/pipelineTool-0.1.0.tar.gz"
    execshell "decompress pipelineTool-0.1.0.tar.gz ${pipelineDir} pipelineTool"
    execshell "rm -f pipelineTool-0.1.0.tar.gz"
fi

ycsbDir=${testOut}/YCSB
if [ ! -d ${ycsbDir} ]; then
    execshell "wget http://pkg.4paradigm.com:81/testbox/YCSB-0.1.0.tar.gz"
    execshell "decompress YCSB-0.1.0.tar.gz ${ycsbDir} YCSB"
    execshell "rm -f YCSB-0.1.0.tar.gz"
fi

ps -ef |grep '0.0.0.0:6666' |grep -v grep |awk '{print $2}' |xargs kill -9 
runenvdir=${testOut}/perftest
logdir=${runenvdir}/log
confile=${curDir}/workload.rtidb
mkdir -p ${logdir}

cd ${rootdir}/build/bin
# nohup ./rtidb --log_level=debug --endpoint=${rtidbIp}:${rtidbPort} --role=tablet > ${logdir}/rtidb.log 2>&1 &
cd ${ycsbDir}
./bin/ycsb load rtidb -P ${confile} -p rtidb.host=${rtidbIp} -p rtidb.port=${rtidbPort} -p rtidb.ttl=${rtidbTTL} -threads ${threads}  -target ${target}  >  ${logdir}/ycsb.log 2>&1
./bin/ycsb run  rtidb -P ${confile} -p rtidb.host=${rtidbIp} -p rtidb.port=${rtidbPort}  -p rtidb.ttl=${rtidbTTL} -threads ${threads} -target ${target} >> ${logdir}/ycsb.log 2>&1
ps -ef |grep '${rtidbIp}:${rtidbPort}' |grep -v grep |awk '{print $2}' |xargs kill -9 
